package com.itheima.health.service.impl;

import com.itheima.health.dao.MemberDao;
import com.itheima.health.dao.OrderDao;
import com.itheima.health.dao.ReportDao;
import com.itheima.health.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.itheima.health.utils.DateUtils;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author deng
 * @package com.itheima.health.service.impl
 * @date Created in 2024/7/15 08:40
 */
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportDao reportDao;

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;


    @Override
    public List<Map> getSetmealReport() {
        List<Map> maps = reportDao.find();
        return maps;
    }

    @Override
    public Map<String, Object> getBusinessReport() throws Exception {
        Date today = DateUtils.getToday();
        Date thisWeekMonday = DateUtils.getThisWeekMonday();
        Date firstDay4ThisMonth = DateUtils.getFirstDay4ThisMonth();

        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        Integer totalMember = memberDao.findMemberTotalCount();
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(thisWeekMonday);
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekMonday);
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);
        List<Map> hotSetmeal = orderDao.findHotSermeal();

        Map<String, Object> result = new HashMap<>();
        result.put("reportDate", DateUtils.getTodayString());
        result.put("todayNewMember", todayNewMember);
        result.put("totalMember", totalMember);
        result.put("thisWeekNewMember", thisWeekNewMember);
        result.put("thisMonthNewMember", thisMonthNewMember);
        result.put("todayOrderNumber", todayOrderNumber);
        result.put("todayVisitsNumber", todayVisitsNumber);
        result.put("thisWeekOrderNumber", thisWeekOrderNumber);
        result.put("thisWeekVisitsNumber", thisWeekVisitsNumber);
        result.put("thisMonthOrderNumber", thisMonthOrderNumber);
        result.put("thisMonthVisitsNumber", thisMonthVisitsNumber);
        result.put("hotSetmeal", hotSetmeal);

        return result;
    }

}
